package com.serookie.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.serookie.entity.GoodsDetails;
import com.serookie.mapper.GoodsDetailsMapper;
import com.serookie.service.GoodsDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author kevintam
 * @version 1.0
 * @date 2021/5/24 19:51
 */
@Service
public class GoodsDetailsServiceImpl implements GoodsDetailsService{

    @Autowired
    private GoodsDetailsMapper detailsMapper;

    @Override
    public List<GoodsDetails> all() {
        return detailsMapper.selectList(null);
    }

    @Override
    public List<GoodsDetails> getByGoodsId(Integer goodsId) {
        QueryWrapper<GoodsDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id",goodsId);
        return detailsMapper.selectList(wrapper);
    }

    @Override
    public Boolean save(GoodsDetails goodsDetails) {
        return detailsMapper.insert(goodsDetails)>0;
    }


    @Override
    public Boolean updateDetails(GoodsDetails goodsDetails) {
        return detailsMapper.updateById(goodsDetails)>0;
    }

    @Override
    public Boolean delDetails(Integer goodsId) {
        QueryWrapper<GoodsDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id",goodsId);
        return detailsMapper.delete(wrapper)>0;
    }

}
